<template>
  <view class="container">
    <z-paging-swiper>
      <view slot="top">
        <u-navbar height="50" title="营销活动" title-size="36" title-color="#333"></u-navbar>
        <view class="" style="background-color: #fff; padding: 20rpx">
          <view class="top-bar">
            <view @click="type = 1" class="bar-item" :class="type == 1 ? `check-item` : ``">
              拼团购
            </view>
            <view @click="type = 2" class="bar-item" :class="type == 2 ? `check-item` : ``">
              限时抢购
            </view>
            <view @click="type = 3" class="bar-item" :class="type == 3 ? `check-item` : ``">
              优惠券
            </view>
          </view>
        </view>

        <u-gap height="20" bg-color="f2f2f2"></u-gap>
        <view v-if="type == 1" class="hanle-bar" @click="routeTo(1, '创建拼团购物', '')">
          <u-icon name="/static/img/ptgd.png" size="40"></u-icon>
          <view class="handle-title"> 拼团购物 </view>
          <view class="handle-btn"> 创建拼团购物 </view>
        </view>
        <view v-else-if="type == 2" class="hanle-bar" @click="routeTo(2, '创建限时抢购', '')">
          <u-icon name="/static/img/ptgd.png" size="40"></u-icon>
          <view class="handle-title"> 限时抢购 </view>
          <view class="handle-btn"> 创建限时抢购 </view>
        </view>
        <view v-else class="hanle-bar" @click="routeTo(3, '创建优惠券', '')">
          <u-icon name="/static/img/yhqtb.png" size="40"></u-icon>
          <view class="handle-title"> 优惠券 </view>
          <view class="handle-btn"> 创建优惠券 </view>
        </view>
        <u-gap height="20" bg-color="f2f2f2"></u-gap>

        <view class="tabsView">
          <u-tabs-swiper
            ref="uTabs"
            :list="tabsList"
            :current="current"
            @change="tabsChange"
            :is-scroll="false"
            :show-bar="false"
            active-color="#0F76BC"
            swiper-width="750"
          >
          </u-tabs-swiper>
        </view>
        <u-gap height="20" bg-color="#F0F1F2"></u-gap>
      </view>
      <swiper
        class="swiperView"
        :current="scurrent"
        @transition="transition"
        @animationfinish="animationfinish"
      >
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging"
            v-model="itemList"
            @query="queryList"
            :fixed="true"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <!-- @click="onOrderDetail(item)" -->
              <view class="itemView" v-for="(item, index1) in itemList" :key="index1">
                <view v-if="type != 3" class="order-top">
                  <view v-if="item.status == 1" class="order-top-tip"> 进行中 </view>
                  <view v-else-if="item.status == 2" class="order-top-tip"> 未开始 </view>
                  <view v-else-if="item.status == 3" class="order-top-tip"> 已结束 </view>
                  <view v-else-if="item.status == 4" class="order-top-tip"> 已下架 </view>
                </view>

                <view v-if="type != 3" class="order-goods">
                  <image class="action-img" src="/static/img/ptgdx.png"></image>
                  <view class="orde-riget">
                    <view class="goods-title"> 活动名称 </view>
                    <view class="goods-speci"> 活动起止时间 </view>
                    <view class="goods-price"> 2023-11-20 - 2023-12-20 </view>
                  </view>
                </view>

                <view v-if="type == 3" class="order-top2">
                  <u-icon name="/static/img/yhq.png" size="28"></u-icon>
                  <text style="font-size: 30rpx; margin: 20rpx 10rpx">满减券</text>
                  <view v-if="item.status == 1" class="order-top-tip2"> 进行中 </view>
                  <view v-else-if="item.status == 2" class="order-top-tip2"> 未开始 </view>
                  <view v-else-if="item.status == 3" class="order-top-tip2"> 已结束 </view>
                  <view v-else-if="item.status == 4" class="order-top-tip2"> 已下架 </view>
                  <view style="flex: 1"> </view>
                  <view
                    v-if="item.status == 1"
                    class="hollow-btn btn"
                    style="color: #f54831; border: #f54831 solid 2rpx"
                  >
                    停止发放
                  </view>
                </view>

                <view v-if="type == 3" class="">
                  <view class="goods-title"> 满20立即减1元 </view>
                  <view class="goods-price" style="margin: 15rpx 0">
                    领券时间：2023-11-20 12:00 至 2023-12-20 12:00
                  </view>
                </view>

                <view class="btn-group" v-if="type != 3">
                  <view
                    class="solid-btn btn"
                    @click="routeTo(type == 1 ? 1 : 2, type == 1 ? '创建团购' : '创建限时购', '')"
                  >
                    修改
                  </view>

                  <view
                    class="hollow-btn btn"
                    @click="
                      routeToCoupon('/other_center/mer-action-order/mer-action-order?type=' + type)
                    "
                  >
                    参与记录
                  </view>
                  <view class="hollow-btn btn"> 下架 </view>
                </view>
                <view v-else class="btn-group">
                  <view class="solid-btn btn"> 修改 </view>
                  <view
                    class="hollow-btn btn"
                    @click="routeToCoupon('/other_center/mer-action-order/mer-action-order?type=3')"
                  >
                    发放明细
                  </view>
                  <view class="hollow-btn btn"> 删除 </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging2"
            v-model="itemList2"
            @query="queryList2"
            :fixed="false"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-for="(item, index1) in itemList"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view v-if="type != 3" class="order-top">
                  <view v-if="item.status == 1" class="order-top-tip"> 进行中 </view>
                  <view v-else-if="item.status == 2" class="order-top-tip"> 未开始 </view>
                  <view v-else-if="item.status == 3" class="order-top-tip"> 已结束 </view>
                  <view v-else-if="item.status == 4" class="order-top-tip"> 已下架 </view>
                </view>

                <view v-if="type != 3" class="order-goods">
                  <image class="action-img" src="/static/img/ptgdx.png"></image>
                  <view class="orde-riget">
                    <view class="goods-title"> 活动名称 </view>
                    <view class="goods-speci"> 活动起止时间 </view>
                    <view class="goods-price"> 2023-11-20 - 2023-12-20 </view>
                  </view>
                </view>

                <view v-if="type == 3" class="order-top2">
                  <u-icon name="/static/img/yhq.png" size="28"></u-icon>
                  <text style="font-size: 30rpx; margin: 20rpx 10rpx">满减券</text>
                  <view v-if="item.status == 1" class="order-top-tip2"> 进行中 </view>
                  <view v-else-if="item.status == 2" class="order-top-tip2"> 未开始 </view>
                  <view v-else-if="item.status == 3" class="order-top-tip2"> 已结束 </view>
                  <view v-else-if="item.status == 4" class="order-top-tip2"> 已下架 </view>
                  <view style="flex: 1"> </view>
                  <view
                    v-if="item.status == 1"
                    class="hollow-btn btn"
                    style="color: #f54831; border: #f54831 solid 2rpx"
                  >
                    停止发放
                  </view>
                </view>

                <view v-if="type == 3" class="">
                  <view class="goods-title"> 满20立即减1元 </view>
                  <view class="goods-price" style="margin: 15rpx 0">
                    领券时间：2023-11-20 12:00 至 2023-12-20 12:00
                  </view>
                </view>

                <view class="btn-group" v-if="type != 3">
                  <view
                    class="solid-btn btn"
                    @click="routeTo(type == 1 ? 1 : 2, type == 1 ? '创建团购' : '创建限时购', '')"
                  >
                    修改
                  </view>

                  <view class="hollow-btn btn"> 参与记录 </view>
                  <view class="hollow-btn btn"> 下架 </view>
                </view>
                <view v-else class="btn-group">
                  <view class="solid-btn btn"> 修改 </view>
                  <view class="hollow-btn btn"> 删除 </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging3"
            v-model="itemList3"
            @query="queryList3"
            :fixed="false"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-for="(item, index1) in itemList"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view class="order-top">
                  <view class=""> 交易单号：200343676738898 </view>

                  <view class="order-top-tip"> 待发货 </view>
                </view>

                <view class="order-goods">
                  <u-icon class="goods-img" name="/static/img/gimg.png" size="160"></u-icon>
                  <view class="orde-riget">
                    <view class="goods-title"> 产品名称餐品名称 </view>
                    <view class="goods-speci">
                      规格
                      <text class="goods-num">x10</text>
                    </view>
                    <view class="goods-price"> ¥88.60 </view>
                  </view>
                </view>

                <view class="price-total">
                  共1样商品 合计：¥690.00
                  <p style="font-size: 24rpx">（含运输费¥10.00）</p>
                </view>

                <view class="btn-group">
                  <view class="solid-btn btn"> 确认发货 </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging4"
            v-model="itemList4"
            @query="queryList4"
            :fixed="false"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-for="(item, index1) in itemList"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view class="order-top">
                  <view class=""> 交易单号：200343676738898 </view>

                  <view class="order-top-tip"> 待收货 </view>
                </view>

                <view class="order-goods">
                  <u-icon class="goods-img" name="/static/img/gimg.png" size="160"></u-icon>
                  <view class="orde-riget">
                    <view class="goods-title"> 产品名称餐品名称 </view>
                    <view class="goods-speci">
                      规格
                      <text class="goods-num">x10</text>
                    </view>
                    <view class="goods-price"> ¥88.60 </view>
                  </view>
                </view>

                <view class="price-total">
                  共1样商品 合计：¥690.00
                  <p style="font-size: 24rpx">（含运输费¥10.00）</p>
                </view>

                <view class="btn-group">
                  <view class="hollow-btn btn"> 修改物流 </view>
                  <view class="hollow-btn btn"> 查看物流 </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging5"
            v-model="itemList5"
            @query="queryList5"
            :fixed="false"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-for="(item, index1) in itemList"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view class="order-top">
                  <view class=""> 交易单号：200343676738898 </view>

                  <view class="order-top-tip"> 待退款 </view>
                </view>

                <view class="order-goods">
                  <u-icon class="goods-img" name="/static/img/gimg.png" size="160"></u-icon>
                  <view class="orde-riget">
                    <view class="goods-title"> 产品名称餐品名称 </view>
                    <view class="goods-speci">
                      规格
                      <text class="goods-num">x10</text>
                    </view>
                    <view class="goods-price"> ¥88.60 </view>
                  </view>
                </view>
                <view class="price-total">
                  共1样商品 申请退款金额：<text style="color: #f54831">¥690.00 </text>
                </view>

                <view class="btn-group">
                  <view class="solid-btn btn"> 查看退款原因 </view>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
        <swiper-item class="swiperItem">
          <z-paging
            ref="paging6"
            v-model="itemList3"
            @query="queryList6"
            :fixed="false"
            :auto="false"
            :empty-view-img="`${getImageUrl('empty.png')} `"
            empty-view-text="暂无订单数据~"
            :empty-view-img-style="imgStyle"
          >
            <view class="goodsItemView">
              <view
                class="itemView"
                v-for="(item, index1) in itemList"
                :key="index1"
                @click="onOrderDetail(item)"
              >
                <view class="order-top">
                  <view class=""> 交易单号：200343676738898 </view>

                  <view class="order-top-tip"> 已完成 </view>
                </view>
                <view class="order-goods">
                  <u-icon class="goods-img" name="/static/img/gimg.png" size="160"></u-icon>
                  <view class="orde-riget">
                    <view class="goods-title"> 产品名称餐品名称 </view>
                    <view class="goods-speci">
                      规格
                      <text class="goods-num">x10</text>
                    </view>
                    <view class="goods-price"> ¥88.60 </view>
                  </view>
                </view>

                <view class="price-total">
                  共1样商品 合计：¥690.00
                  <p style="font-size: 24rpx">（含运输费¥10.00）</p>
                </view>
              </view>
            </view>
          </z-paging>
        </swiper-item>
      </swiper>
    </z-paging-swiper>
  </view>
</template>

<script>
export default {
  data() {
    return {
      checkIndex: 1,
      imgStyle: {
        width: '12rem'
      },
      type: 1,
      current: 0,
      scurrent: 0,
      tabsList: [
        {
          name: '全部'
        },
        {
          name: '进行中'
        },
        {
          name: '未开始'
        },
        {
          name: '已结束'
        }
      ],
      itemList: [
        {
          status: 1
        },
        {
          status: 2
        },
        {
          status: 3
        },
        {
          status: 4
        }
      ],
      itemList2: [
        {
          status: 1
        }
      ],
      itemList3: [
        {
          status: 2
        }
      ],
      itemList4: [
        {
          status: 3
        }
      ],
      itemList5: [
        {
          status: 4
        }
      ],
      order_id: ''
    }
  },
  onLoad(res) {
    let self = this
    this.$nextTick(function () {
      self.current = Number(res.index) ? Number(res.index) : 0
      self.scurrent = Number(res.index) ? Number(res.index) : 0
      //self.onOrderLoad(self.current, null, true);
    })
  },
  onShow() {
    let self = this
    this.$nextTick(function () {
      //self.onOrderLoad(self.current, null, true);
    })
  },
  methods: {
    tabsChange(index) {
      this.scurrent = index
    },
    transition(e) {
      let dx = e.detail.dx
      this.$refs.uTabs.setDx(dx)
    },
    animationfinish(e) {
      let current = e.detail.current
      this.current = current
      this.scurrent = current
      this.$refs.uTabs.setFinishCurrent(current)
      if (this.current != current) {
        this.onOrderLoad(current, null, true)
      }
      this.scurrent = current
      this.current = current
    },
    queryList(page, pageSize) {
      this.initData(page, pageSize, '')
    },
    queryList2(page, pageSize) {
      this.initData(page, pageSize, '0')
    },
    queryList3(page, pageSize) {
      this.initData(page, pageSize, '1')
    },
    queryList4(page, pageSize) {
      this.initData(page, pageSize, '2')
    },
    queryList5(page, pageSize) {
      this.initData(page, pageSize, '3')
    },
    queryList6(page, pageSize) {
      this.initData(page, pageSize, '3')
    },
    initData(page, pageSize, status) {
      // let self = this;
      // self.$u.api.getOrderList({
      // 	limit: pageSize,
      // 	page: page,
      // 	status: status
      // }).then(res => {
      // 	self.onOrderLoad(self.current, res.list, false);
      // }).catch(res => {
      // 	self.onOrderLoad(self.current, null, false);
      // });
    },
    onOrderLoad(current, orderList, loading) {
      let self = this
      switch (Number(current)) {
        case 0:
          if (loading) {
            self.$refs.paging.reload()
          } else {
            self.$refs.paging.complete(orderList)
          }
          break
        case 1:
          if (loading) {
            self.$refs.paging2.reload()
          } else {
            self.$refs.paging2.complete(orderList)
          }
          break
        case 2:
          if (loading) {
            self.$refs.paging3.reload()
          } else {
            self.$refs.paging3.complete(orderList)
          }
          break
        case 3:
          if (loading) {
            self.$refs.paging4.reload()
          } else {
            self.$refs.paging4.complete(orderList)
          }
          break
        case 4:
          if (loading) {
            self.$refs.paging5.reload()
          } else {
            self.$refs.paging5.complete(orderList)
          }
          break
      }
    },
    onOrderCancel(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '确定要取消订单吗？', () => {
        self.$u.api.setOrderCancel(item.id).then((res) => {
          self.$u.toast('取消成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onOrderPayment(item) {
      let self = this
      // self.$u.api.setTestPayments({
      // 	order_no: item.order_no,
      // 	openid: uni.getStorageSync('openid')
      // }).then(res => {
      // 	setTimeout(function() {
      // 		self.onOrderLoad(self.current, null, true);
      // 	}, 500);
      // });
      this.$utils.route({
        url: '/goods/payment/payment',
        params: {
          order_id: item.id,
          money: item.pay_price,
          total_weight: item.total_weight,
          delivery_price: item.delivery_price
        }
      })
    },
    onOrderConfrim(item) {
      let self = this
      uni.dialog.confirm('温馨提示', '该订单确认收货吗？', () => {
        self.$u.api.setOrderConfirm(item.id).then((res) => {
          self.$u.toast('收货成功')
          setTimeout(function () {
            self.onOrderLoad(self.current, null, true)
          }, 500)
        })
      })
    },
    onResellPush(item) {
      this.$utils.route({
        url: '/goods/resell-push/resell-push',
        params: {
          id: item.id
        }
      })
    },
    onPushComment(item) {
      this.$utils.route({
        url: '/other/push-comment/push-comment',
        params: {
          id: item.id
        }
      })
    },
    onOrderDetail(item) {
      this.$utils.route({
        url: '/other_center/mer-order-details/mer-order-details',
        params: {
          id: item.id
        }
      })
    },
    routeToCoupon(url) {
      this.$utils.route({ url })
    },
    routeTo(type, title, data) {
      this.$utils.route({
        url: '/other_center/mer-action-manage/mer-action-manage',
        params: {
          type,
          title,
          data
        }
      })
    }
  }
}
</script>

<style>
page {
  height: 100%;
  background: #f0f1f2;
}
.top-bar {
  display: flex;
  width: 690rpx;
  height: 80rpx;
  border: 2rpx #0f76bc solid;
  border-radius: 40rpx;
  font-size: 32rpx;
  line-height: 80rpx;
}
.bar-item {
  flex: 1;
  text-align: center;
}
.check-item {
  background-color: #0f76bc;
  color: #fff;
  border-radius: 40rpx;
}

.hanle-bar {
  display: flex;
  align-items: center;
  padding: 20rpx;
  background-color: #fff;
}
.handle-title {
  flex: 1;
  font-size: 32rpx;
  margin-left: 10rpx;
}
.handle-btn {
  padding: 8rpx 20rpx;
  background-color: #8cc340;
  color: #fff;
  border-radius: 35rpx;
}

.tabsView {
  display: flex;
  flex-direction: column;
  background: #ffffff;
  height: 90rpx;
}

.goodsItemView {
  display: flex;
  flex-direction: column;
}

.itemView {
  display: flex;
  flex-direction: column;
  background-color: #ffffff;
  margin-bottom: 1rem;
  border-radius: 6px;
  padding: 20rpx;
}

.order-top {
  position: relative;
  padding: 15rpx 0;
  font-size: 30rpx;
}

.order-top2 {
  display: flex;
  align-items: center;
}

.order-top-tip {
  display: inline-block;
  position: absolute;
  top: 15rpx;
  right: 0;
  color: #666666;
  background-color: #e6e6e6;
  padding: 5rpx 18rpx;
  font-size: 20rpx;
  border-radius: 20rpx;
}

.order-top-tip2 {
  display: inline-block;
  color: #666666;
  background-color: #e6e6e6;
  padding: 5rpx 18rpx;
  font-size: 20rpx;
  border-radius: 20rpx;
}

.order-goods {
  display: flex;
  margin-bottom: 15rpx;
}

.action-img {
  width: 280rpx;
  height: 180rpx;
  flex-shrink: 0;
  border-radius: 8rpx;
}

.orde-riget {
  width: 100%;
  margin-left: 10rpx;
  line-height: 55rpx;
  font-size: 26rpx;
}

.goods-title {
  font-size: 30rpx;
}
.goods-speci {
  font-size: 26rpx;
  color: #666666;
}

.goods-price {
  font-size: 24rpx;
  color: #999999;
}
.price-total {
  padding: 20rpx 0;
  border-top: #ededed solid 2rpx;
  border-bottom: #ededed solid 2rpx;
  text-align: right;
  font-size: 28rpx;
  margin: 15rpx 0;
}

.btn-group {
  display: flex;
  flex-direction: row-reverse;
  border-top: #ededed solid 2rpx;
  padding: 20rpx 0;
}

.btn {
  display: inline-block;
  padding: 5rpx 20rpx;
  border-radius: 35rpx;
  font-size: 26rpx;
  margin-left: 15rpx;
}
.hollow-btn {
  color: #666666;
  border: #e6e6e6 solid 2rpx;
}
.solid-btn {
  background-color: #0f76bc;
  color: #fff;
}
</style>
